package leetcode.jianzhioffer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @program: javase
 * @description: 剑指offer09
 * @author: hmx
 * @create: 2021-08-12 17:36
 **/
public class JianZhiOffer09 {

    Deque<Integer> stackIn = null;
    Deque<Integer> stackOut = null;
    public JianZhiOffer09() {
        stackIn = new LinkedList<>();
        stackOut = new LinkedList<>();
    }

    public void appendTail(int value) {
        stackIn.push(value);
    }

    public int deleteHead() {
        if (stackOut.size() > 0) {
            return stackOut.pop();
        } else if (stackIn.size() > 0) {
            while (stackIn.size() > 0) {
                stackOut.push(stackIn.pop());
            }
        }
        return stackOut.size() > 0? stackOut.pop():-1;
    }

    public static void main(String[] args) {
        JianZhiOffer09 collectionTest = new JianZhiOffer09();
        collectionTest.appendTail(3);
        System.out.println(collectionTest.deleteHead());
        System.out.println(collectionTest.deleteHead());

    }
}
